﻿
using Microsoft.AspNetCore.Mvc.Filters;

namespace mvc6.Filters
{
    public class MyActionFilter : Attribute, IActionFilter
    {

        private static Dictionary<string,object> dict = new Dictionary<string, object>();

        public void OnActionExecuted(ActionExecutedContext context)
        {
            Console.WriteLine($"{context.ActionDescriptor.DisplayName} 方法调用完");
            string path = context.HttpContext.Request.Path;
            dict[path] = context.Result;
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            Console.WriteLine($"{context.ActionDescriptor.DisplayName} 方法调用中");
            string path = context.HttpContext.Request.Path;
            if (dict.ContainsKey(path))
            {
                context.Result = (Microsoft.AspNetCore.Mvc.IActionResult?)dict[path];
            }
        }
    }
}
